﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Simulacion.NumberGenerator;

namespace Simulacion.Distributions
{
    /// <summary>
    ///  Generic class of the Triangular distribution.
    /// </summary>
    class Triangular
    {
        public static double fTriangular(double x, double a, double b, double c)
        {
            return (a <= x && x <= b) ? (2.0F * (x - a)) / ((b - a) * (c - a)) : (2.0F * (c - x)) / ((c - b) * (c - a)) ;
        }
        /// <summary>
        /// Gets the value using the Triangular distribution.
        /// </summary>
        /// <returns>The value of the distribution.</returns>
        public static double GetDistributionValue(double a, double b, double c)
        {
            double R = Generator.NextNumber;

            return (( 0 <= R && R <= (b - a) / (c - a)) ? Math.Sqrt(R * (b - a) * (c - a)) + a : Math.Sqrt((c - b) * (R * (c - a) - (b - a))) + b) / 7;
        }
    }
}
